package com.bridge.common.sms;


import com.alibaba.fastjson.JSONObject;

/**
 * @author sunke
 * @date 2016-4-12 下午6:00:38
 * @description
 */
public class SmsFactory {

    private static SmsFactory factory = null;

    public static SmsFactory getInstance() {
        if (factory == null) {

            factory = new SmsFactory();

        }

        return factory;

    }

    public boolean bindPhone(String phone, String code) {
        if (phone == null || "".equals(phone))
            return false;

        try {
            BindPhoneSms sms = new BindPhoneSms(code);
            sms.setToPhone(phone);


            sms.sendSms();

            return true;


        } catch (Exception e) {


        }


        return false;


    }
    public boolean smsLogin(String phone, JSONObject jsonObject, SmsInfo smsInfo) {
        if (phone == null || "".equals(phone))
            return false;

        try {
            AbstractSms sms = (AbstractSms) Class.forName("com.rebar.common.sms."+smsInfo.getServiceImpl()).newInstance();
            sms.setTemplateParam(jsonObject);
            sms.setToPhone(phone);
            sms.sendSms();
            return true;
        } catch (Exception e) {
            e.printStackTrace();

        }
        return false;
    }

    public boolean smsString(String phone, String code , SmsInfo smsInfo) {
        if (phone == null || "".equals(phone))
            return false;
        try {
            AbstractSms sms = (AbstractSms) Class.forName("com.rebar.common.sms."+smsInfo.getServiceImpl()).newInstance();
            sms.setCode(code);
            sms.setSmsInfo(smsInfo);
            sms.setToPhone(phone);
            sms.sendSms();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
